package com.rh.schedule;

import com.rh.service.StatisticsDailyService;
import com.rh.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时任务类
 */
@Component
@Slf4j
public class ScheduleTask {
   @Autowired
    private StatisticsDailyService statisticsDailyService;

   //每天凌晨1点,执行方法把数据查询出来进行添加
    @Scheduled(cron = "0 0 1 * * ?")
    public void task(){
        //获取当前日期-1
        String date = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        statisticsDailyService.registerCount(date);
        log.info("定时添加数据.....");
    }
}

